<!DOCTYPE html>
<html lang="zh-cmn-Hans">
<head>
	<meta charset="UTF-8">
	<link rel="shortcut icon" href="favicon.ico">
	<link rel="stylesheet" href="css/iconfont.css">
	<link rel="stylesheet" href="css/global.css">
	<link rel="stylesheet" href="css/bootstrap.min.css">
	<link rel="stylesheet" href="css/bootstrap-theme.min.css">
	<link rel="stylesheet" href="css/swiper.min.css">
	<link rel="stylesheet" href="css/styles.css">
	<link rel="stylesheet" href="css/logo.css" />
	<script src="js/jquery.1.12.4.min.js" charset="UTF-8"></script>
	<script src="js/bootstrap.min.js" charset="UTF-8"></script>
	<script src="js/swiper.min.js" charset="UTF-8"></script>
	<script src="js/global.js" charset="UTF-8"></script>
	<script src="js/jquery.DJMask.2.1.1.js" charset="UTF-8"></script>
	<title>XXX</title>
</head>
<body>
	<!-- 顶部tab -->

	<div id="tbb">
	
	</div>
	<!-- 顶部标题 -->
	<div class="bgf5 clearfix">
		<div class="top-user">
			<div class="inner">
				<a class="logo" href="index.html"> <li id="logo"></li> </a>
				<div class="title">购物车</div>
			</div>
		</div>
	</div>
	<div class="content clearfix bgf5">
		<section class="user-center inner clearfix">
			<div class="user-content__box clearfix bgf">
				<div class="title">购物车</div>
				<form action="" class="shopcart-form__box">
					<table class="table table-bordered">
						<thead>
							<tr>
								<th width="150">
									<label class="checked-label"><input type="checkbox" class="check-all"  id="qx"><i></i> 全选</label>
								</th>
								<th width="300">商品信息</th>
								<th width="150">单价</th>
								<th width="200">数量</th>
								<th width="200">总价</th>
								<th width="80">操作</th>
							</tr>
						</thead>
						<tbody id="tbody">
							
						</tbody>
					</table>
					<div class="user-form-group tags-box shopcart-submit pull-right">
						<button type="button" class="btn">提交订单</button>
					</div>
					<div class="checkbox shopcart-total">
						
						&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href="" id="qxsc">删除</a>
						<div class="pull-right">
							已选商品 <span id="gs">0</span> 件
							&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;合计（不含运费）
							<b class="cr">¥<span class="fz24" id="zj">0</span></b>
						</div>
					</div>
					
				</form>
			</div>
		</section>
	</div>
	<!-- 右侧菜单 -->
	<div class="right-nav">
		<ul class="r-with-gotop">
			<li class="r-toolbar-item">
				<a href="udai_welcome.html" class="r-item-hd">
					<i class="iconfont icon-user" data-badge="0"></i>
					<div class="r-tip__box"><span class="r-tip-text">用户中心</span></div>
				</a>
			</li>
			<li class="r-toolbar-item">
				<a href="udai_shopcart.html" class="r-item-hd">
					<i class="iconfont icon-cart"></i>
					<div class="r-tip__box"><span class="r-tip-text">购物车</span></div>
				</a>
			</li>
			<li class="r-toolbar-item">
				<a href="udai_collection.html" class="r-item-hd">
					<i class="iconfont icon-aixin"></i>
					<div class="r-tip__box"><span class="r-tip-text">我的收藏</span></div>
				</a>
			</li>
			<li class="r-toolbar-item">
				<a href="" class="r-item-hd">
					<i class="iconfont icon-liaotian"></i>
					<div class="r-tip__box"><span class="r-tip-text">联系客服</span></div>
				</a>
			</li>
			<li class="r-toolbar-item">
				<a href="issues.html" class="r-item-hd">
					<i class="iconfont icon-liuyan"></i>
					<div class="r-tip__box"><span class="r-tip-text">留言反馈</span></div>
				</a>
			</li>
			<li class="r-toolbar-item to-top">
				<i class="iconfont icon-top"></i>
				<div class="r-tip__box"><span class="r-tip-text">返回顶部</span></div>
			</li>
		</ul>
		<script>
			$(document).ready(function(){ $('.to-top').toTop({position:false}) });
		</script>
	</div>
	<!-- 底部信息 -->
	<div class="footer">
		<div class="footer-tags">
			<div class="tags-box inner">
				<div class="tag-div">
					<img src="images/icons/footer_1.gif" alt="厂家直供">
				</div>
				<div class="tag-div">
					<img src="images/icons/footer_2.gif" alt="一件代发">
				</div>
				<div class="tag-div">
					<img src="images/icons/footer_3.gif" alt="美工活动支持">
				</div>
				<div class="tag-div">
					<img src="images/icons/footer_4.gif" alt="信誉认证">
				</div>
			</div>
		</div>
		<div class="footer-links inner">
			<dl>
				<dt>XXX</dt>
				<a href="temp_article/udai_article10.html"><dd>企业简介</dd></a>
				<a href="temp_article/udai_article11.html"><dd>加入U袋</dd></a>
				<a href="temp_article/udai_article12.html"><dd>隐私说明</dd></a>
			</dl>
			<dl>
				<dt>服务中心</dt>
				<a href="temp_article/udai_article1.html"><dd>售后服务</dd></a>
				<a href="temp_article/udai_article2.html"><dd>配送服务</dd></a>
				<a href="temp_article/udai_article3.html"><dd>用户协议</dd></a>
				<a href="temp_article/udai_article4.html"><dd>常见问题</dd></a>
			</dl>
			<dl>
				<dt>新手上路</dt>
				<a href="temp_article/udai_article5.html"><dd>如何成为代理商</dd></a>
				<a href="temp_article/udai_article6.html"><dd>代销商上架教程</dd></a>
				<a href="temp_article/udai_article7.html"><dd>分销商常见问题</dd></a>
				<a href="temp_article/udai_article8.html"><dd>付款账户</dd></a>
			</dl>
		</div>
		<div class="copy-box clearfix">
			<ul class="copy-links">
				<a href="agent_level.html"><li>网店代销</li></a>
				<a href="class_room.html"><li>U袋学堂</li></a>
				<a href="udai_about.html"><li>联系我们</li></a>
				<a href="temp_article/udai_article10.html"><li>企业简介</li></a>
				<a href="temp_article/udai_article5.html"><li>新手上路</li></a>
			</ul>
			<!-- 版权 -->
			<p class="copyright">
				© 2005-2017 XXX 版权所有，并保留所有权利<br>
				ICP备案证书号：闽ICP备XXX号-2&nbsp;&nbsp;&nbsp;&nbsp;福建省宁德市XXX&nbsp;&nbsp;&nbsp;&nbsp;Tel: XXX&nbsp;&nbsp;&nbsp;&nbsp;E-mail: XXX@qq.com
			</p>
		</div>
	</div>
</body>
<script type="text/javascript">
	function getCookie(cookieName) {
    var strCookie = document.cookie;
    var arrCookie = strCookie.split("; ");
    for(var i = 0; i < arrCookie.length; i++){
        var arr = arrCookie[i].split("=");
        if(cookieName == arr[0]){
            return arr[1];
        }
    }
    return "";
}
	
	var userid = getCookie("userid");
	
 //alert(userid);
	
	
	//alert(sessionStorage.getItem("userid"));
	$("#tbb").load("index_head.html");
	 var i = 1;
 if(i===1)
 {
 	showshopping();
 	i=2;
 }
 
 function showshopping () {
 	$.ajax({
					xhrFields:{withCredentials: true},
				    type: "post",//请求方式
				    url: "http://localhost:16111/pay/pay/showshopping",//上s层的路径
					dataType: "json",
				    data:{
				    	user_id:userid
				    	},//传值
				    success: function (data)
					{
						var dataObj=eval("("+JSON.stringify(data)+")");
 		
 		var tbody = document.getElementById("tbody");
 		
 		if (dataObj.code>0) {
 			for (var x=0;x<dataObj.data.length;x++) {
 				
 				var tr = document.createElement("tr");
	 			var th = document.createElement("td");
	 			var label = document.createElement("label");
	 			var input1 = document.createElement("input");
	 			var i = document.createElement("i");
	 			var div1 = document.createElement("div");
	 			var img = document.createElement("img");
	 			var td1 = document.createElement("td");
	 			var div2 = document.createElement("div");
	 			var div3 = document.createElement("div");
	 			var td2 = document.createElement("td");
	 			var td3 = document.createElement("td");
	 			var div4 = document.createElement("div");
	 			
	 			var input3 = document.createElement("input");
	 			
	 			var td4 = document.createElement("td");
	 			var span = document.createElement("span");
	 			var td5 = document.createElement("td");
	 			var a = document.createElement("a");
	 			th.scope="row";
	 			label.className="checked-label";
	 			input1.type="checkbox";
	 			input1.name="ids";
	 			input1.className="kuang";
	 			input1.value=dataObj.data[x].cart_id;
	 			div1.className="img";
	 			
	 			img.src=dataObj.data[x].commodity_picture;
	 			img.className="cover";
	 			div2.className="name ep3";
	 			div2.innerHTML=dataObj.data[x].commodity_nametop+" "+dataObj.data[x].commodity_description;
	 			div3.className="type c9";
	 			div3.innerHTML=dataObj.data[x].commodity_leixin;
	 			td2.innerHTML="￥"+dataObj.data[x].collection_item_price;
	 			div4.className="cart-num__box";
	 			
	 			input3.type="text";
	 			input3.className="val";
	 			input3.value=dataObj.data[x].quantity_of_goods;
	 			input3.readOnly="readonly";
	 			input3.maxLength="2";
	 			
	 			
	 			td4.innerHTML="￥";
	 			span.innerHTML=dataObj.data[x].quantity_of_goods*dataObj.data[x].collection_item_price;
	 			span.className="zj2";
	 			a.innerHTML="删除";
	 			a.href="#";
	 			a.className="shoppingdel";
	 			
	 			tr.appendChild(th);
	 			tr.appendChild(td1);
	 			tr.appendChild(td2);
	 			tr.appendChild(td3);
	 			tr.appendChild(td4);
	 			tr.appendChild(td5);
	 			th.appendChild(label);
	 			label.appendChild(input1);
	 			label.appendChild(i);
	 			label.appendChild(div1);
	 			div1.appendChild(img);
	 			
	 			td1.appendChild(div2);
	 			td1.appendChild(div3);
	 			td3.appendChild(div4);
	 			
	 			div4.appendChild(input3);
	 			td4.appendChild(span);
	 			td5.appendChild(a);
	 			
	 			tbody.appendChild(tr);
 			}
 			
 			//document.getElementById("zj").innerHTML=
 			
 			
 		}else{
 			alert(dataObj.error);
 			return;
 		}
		           		
					}
					})
 	
 }
 
 $(function() {
        $("#qx").click(function() {
            $(":checkbox[name='ids']").prop("checked", this.checked); // this指代的你当前选择的这个元素的JS对象
        });
        
        
   });
   var a = new Array();
   
   $(document).on("click",".kuang",function () {
   	var q = 0;
   	var qian = 0;
   	a=[];
   	$(".kuang").each(function()
   	{
		if($(this).prop('checked')==true)
		{
			a[q]=$(this).val();
			//alert(a[q])
//			alert($(this).val())
			q+=1;
			qian+=parseInt($(this).parent().parent().siblings().children(".zj2").text());
		}
   	});	
   
   document.getElementById("gs").innerHTML=q;
   document.getElementById("zj").innerHTML=qian;
   });
   
   
   
   $(document).on("click","#qx",function () {
   	var oo = 0;
   	var ii = 0;
   	a=[];
   	$(".kuang").each(function()
   	{
		if($(this).prop('checked')==true)
		{
			a[oo]=$(this).val();
			//alert(a[oo])
			
			oo+=1;
			ii+=parseInt($(this).parent().parent().siblings().children(".zj2").text());
		}
										
																		
   	});
   //	alert(a.length);	
   	document.getElementById("zj").innerHTML=ii;			
   document.getElementById("gs").innerHTML=oo;
   });
   
   $(document).on("click","#qxsc",function () {
   	
   	
   for (var e = 0; e < a.length; e++) {
   	$.ajax({
					xhrFields:{withCredentials: true},
				    type: "post",//请求方式
				    url: "http://localhost:16111/pay/pay/shoppingdel",//上s层的路径
					dataType: "json",
				    data:{cart_id:a[e]},//传值   				    
				    success: function (data)
					{
						var dataObj=eval("("+JSON.stringify(data)+")");
   			if (dataObj.code>0) {
   				alert(dataObj.error);
   				window.location.href="udai_shopcart.html";
   			}
		           		
					}
					})
   	
// 		$.post("http://localhost:16800/pay/shoppingdel",
// 		
// 		{
// 			cart_id:a[e]
// 		},
// 		function (data) {
// 			var dataObj=eval("("+JSON.stringify(data)+")");
// 			if (dataObj.code>0) {
// 				alert(dataObj.error);
// 				window.location.href="udai_shopcart.html";
// 			}
// 		});
   }
   });
   
   
   
   $(document).on("click",".shoppingdel",function () {
   		 
		if($(this).parent().prev().prev().prev().prev().prev().find(".kuang").prop('checked')==true)
		{
			var cart_ids=$(this).parent().prev().prev().prev().prev().prev().find(".kuang").val();
			$.ajax({
					xhrFields:{withCredentials: true},
				    type: "post",//请求方式
				    url: "http://localhost:16111/pay/pay/shoppingdel",//上s层的路径
					dataType: "json",
				    data:{cart_id:cart_ids},//传值   				    
				    success: function (data)
					{
						var dataObj=eval("("+JSON.stringify(data)+")");
   			if (dataObj.code>0) {
   			//	alert(dataObj.error);
   				window.location.href="udai_shopcart.html";
   			}
		           		
					}
					})
			
//			$.post("http://localhost:16800/pay/shoppingdel",
//			
// 		{
// 			cart_id:cart_ids
// 		},
// 		function (data) {
// 			var dataObj=eval("("+JSON.stringify(data)+")");
// 			if (dataObj.code>0) {
// 				alert(dataObj.error);
// 				window.location.href="udai_shopcart.html";
// 			}
// 		});
		}
  

   		
   })

	$(document).on("click",".btn",function () {
	//	alert(a.length);
		if (a.length>0) {
			window.location.href="shopping_cart_pay.html?cart_id="+a.join(",");
		}
	})
</script>




<!--<script>
						$(document).ready(function(){
							var $item_checkboxs = $('.shopcart-form__box tbody input[type="checkbox"]'),
								$check_all = $('.check-all');
							// 全选
							$check_all.on('change', function() {
								$check_all.prop('checked', $(this).prop('checked'));
								$item_checkboxs.prop('checked', $(this).prop('checked'));
							});
							// 点击选择
							$item_checkboxs.on('change', function() {
								var flag = true;
								$item_checkboxs.each(function() {
									if (!$(this).prop('checked')) { flag = false }
								});
								$check_all.prop('checked', flag);
							});
							// 个数限制输入数字
							$('input.val').onlyReg({reg: /[^0-9.]/g});
							// 加减个数
							$('.cart-num__box').on('click', '.sub,.add', function() {
								var value = parseInt($(this).siblings('.val').val());
								if ($(this).hasClass('add')) {
									$(this).siblings('.val').val(Math.min((value += 1),99));
								} else {
									$(this).siblings('.val').val(Math.max((value -= 1),1));
								}
							});
						});
					</script>-->
</html>